m = int(input())
n = int(input())

if m>n:
    beichu = m
    chu = n
else:
    beichu = n
    chu = m

while True:
    yu = beichu%chu
    if yu<=0:
        break
    beichu = chu
    chu = yu
print(chu)
